from typing import List


class Solution:
    def minEatingSpeed(self, piles: List[int], h: int) -> int:
        left = 0
        right = max(piles) + 1
        while left + 1 < right:
            mid = (left + right) // 2
            if self.can_eating_all_piles(piles, mid, h):
                right = mid
            else:
                left = mid
        return right

    def can_eating_all_piles(self, piles: List[int], k: int, h: int):
        use_time = 0
        for pile in piles:
            use_time += (pile - 1) // k + 1
        return use_time <= h
